home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 18 / CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso / CUCD / Online / hsc / source / hsclib / hscprc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-02  |  18.9 KB  |  884 lines

  1. /*
  2.  * This source code is part of hsc, a html-preprocessor,
  3.  * Copyright (C) 1995-1997  Thomas Aglassinger
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or
  8.  * (at your option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  */
  20. /*
  21.  * hscprc.c
  22.  *
  23.  * hsc process functions
  24.  *
  25.  * updated:  5-Oct-1997
  26.  * created: 11-Feb-1996
  27.  */
  28.  
  29. #define NOEXTERN_HSCLIB_HSCPRC
  30.  
  31. #include "hsclib/inc_base.h"
  32.  
  33. #include "ugly/fname.h"
  34. #include "ugly/ustrlist.h"
  35. #include "ugly/returncd.h"
  36.  
  37. #include "hscprj/project.h"
  38.  
  39. #include "hsclib/idref.h"
  40. #include "hsclib/tag_if.h"
  41.  
  42. /*
  43.  * del_inpf_stack_node
  44.  *
  45.  * remove node from input file stack
  46.  */
  47. static VOID del_inpf_stack_node(APTR data)
  48. {
  49.     /* do nufin */
  50. }
  51.  
  52. /*
  53.  * del_hscprc
  54.  *
  55.  * remove hsc process and all it's resources
  56.  */
  57. VOID del_hscprc(HSCPRC * hp)
  58. {
  59.     if (hp)
  60.     {
  61.         /* remove list */
  62.         del_dllist(hp->defent);
  63.         del_dllist(hp->deftag);
  64.         del_dllist(hp->defattr);
  65.         del_dllist(hp->deflazy);
  66.         del_dllist(hp->container_stack);
  67.         del_dllist(hp->content_stack);
  68.         del_dllist(hp->inpf_stack);
  69.         del_dllist(hp->idrefs);
  70.         del_dllist(hp->select_stack);
  71.         del_strlist(hp->include_dirs);
  72.  
  73.         /* remove strings */
  74.         del_estr(hp->destdir);
  75.         del_estr(hp->reldir);
  76.         del_estr(hp->iconbase);
  77.         del_estr(hp->server_dir);
  78.         del_estr(hp->if_stack);
  79.         del_estr(hp->tag_name_str);
  80.         del_estr(hp->tag_attr_str);
  81.         del_estr(hp->tag_close_str);
  82.         del_estr(hp->tmpstr);
  83.         del_estr(hp->curr_msg);
  84.         del_estr(hp->curr_ref);
  85.         del_estr(hp->whtspc);
  86.  
  87.         ufreestr(hp->filename_document);
  88.         ufreestr(hp->strip_tags);
  89.  
  90.         /* remove project-data */
  91.         del_project(hp->project);
  92.  
  93.         /* close input files */
  94.         infclose(hp->inpf);
  95.  
  96.         /* remove message arrays */
  97.         ufree(hp->msg_ignore);
  98.         ufree(hp->msg_class);
  99.  
  100.         ufree(hp);
  101.     }
  102. }
  103.  
  104. /*
  105.  * reset_hscprc
  106.  *
  107.  * reset all items of a hsc process
  108.  */
  109. VOID reset_hscprc(HSCPRC * hp)
  110. {
  111.     int i;
  112.  
  113.     /* get current time */
  114.     hp->start_time = time(NULL);
  115.  
  116.     /* reset strings */
  117.     clr_estr(hp->destdir);
  118.     clr_estr(hp->reldir);
  119.     clr_estr(hp->if_stack);
  120.     clr_estr(hp->whtspc);
  121.  
  122.     hp->suppress_output = TRUE;
  123.     hp->fatal = FALSE;
  124.     hp->prev_heading_num = 0;
  125.     hp->prev_status_line = (ULONG) - 1;
  126.     hp->msg_count = 0;
  127.  
  128.     hp->inside_pre = FALSE;
  129.     hp->inside_anchor = FALSE;
  130.     hp->inside_title = FALSE;
  131.  
  132.     hp->tag_next_whtspc = NULL;
  133.     hp->strip_badws = FALSE;
  134.     hp->strip_next_whtspc = FALSE;
  135.     hp->strip_next2_whtspc = FALSE;
  136.  
  137.     ufreestr(hp->strip_tags);
  138.  
  139.     /* check for prostitute */
  140.     hp->prostitute = (getenv(ENV_HSCSALARY) != NULL);
  141.  
  142.     /* reset messages */
  143.     hp->msg_ignore_notes = FALSE;
  144.     hp->msg_ignore_style = FALSE;
  145.     hp->msg_ignore_port = FALSE;
  146.     for (i = 0; i <= MAX_MSGID; i++)
  147.     {
  148.         hp->msg_ignore[i] = FALSE;
  149.         hp->msg_class[i] = MSG_NOTE;
  150.     }
  151. }
  152.  
  153. /*
  154.  * new_hscprc
  155.  *
  156.  * create and init a new hsc process
  157.  */
  158. HSCPRC *new_hscprc(void)
  159. {
  160.     HSCPRC *hp = NULL;
  161.  
  162.     hp = (HSCPRC *) umalloc(sizeof(HSCPRC));
  163.     if (hp)
  164.     {
  165.         memset(hp, 0, sizeof(HSCPRC));
  166.  
  167.         /* init lists */
  168.         hp->defent = init_dllist(del_entity);
  169.         hp->deftag = init_dllist(del_hsctag);
  170.         hp->defattr = init_dllist(del_hscattr);
  171.         hp->deflazy = init_dllist(del_hsctag);
  172.         hp->container_stack = init_dllist(del_hsctag);
  173.         hp->content_stack = init_dllist(del_string_node);
  174.         hp->inpf_stack = init_dllist(del_inpf_stack_node);
  175.         hp->project = NULL;
  176.         hp->idrefs = init_dllist(del_idref);
  177.         hp->select_stack = init_dllist(del_select_stack_node);
  178.         hp->include_dirs = init_strlist();
  179.  
  180.         /* init strings */
  181.         hp->destdir = init_estr(0);
  182.         hp->reldir = init_estr(0);
  183.         hp->iconbase = init_estr(0);
  184.         hp->server_dir = init_estr(0);
  185.         hp->if_stack = init_estr(0);
  186.         hp->tag_name_str = init_estr(128);
  187.         hp->tag_attr_str = init_estr(128);
  188.         hp->tag_close_str = init_estr(0);
  189.         hp->tmpstr = init_estr(0);
  190.         hp->curr_msg = init_estr(64);
  191.         hp->curr_ref = init_estr(64);
  192.         hp->whtspc = init_estr(0);
  193.  
  194. #if 0                           /* TODO:remove */
  195.         hp->filename_project = NULL;
  196.         hp->filename_document = NULL;
  197. #endif
  198.  
  199.         /* alloc message arrays */
  200.         hp->msg_ignore = (HSCIGN *)
  201.             umalloc((MAX_MSGID + 1) * sizeof(HSCIGN));
  202.         hp->msg_class = (HSCMSG_CLASS *)
  203.             umalloc((MAX_MSGID + 1) * sizeof(HSCMSG_CLASS));
  204.  
  205.         reset_hscprc(hp);
  206.     }
  207.     return (hp);
  208. }
  209.  
  210. /*
  211.  *
  212.  * GET-methodes for public item of HSCPRC
  213.  *
  214.  */
  215.  
  216. /*
  217.  * get flags
  218.  */
  219. BOOL hsc_get_chkid(HSCPRC * hp)
  220. {
  221.     return (hp->chkid);
  222. }
  223.  
  224. BOOL hsc_get_chkuri(HSCPRC * hp)
  225. {
  226.     return (hp->chkuri);
  227. }
  228.  
  229. BOOL hsc_get_compact(HSCPRC * hp)
  230. {
  231.     return (hp->compact);
  232. }
  233.  
  234. BOOL hsc_get_debug(HSCPRC * hp)
  235. {
  236.     return (hp->debug);
  237. }
  238.  
  239. BOOL hsc_get_getsize(HSCPRC * hp)
  240. {
  241.     return (hp->getsize);
  242. }
  243.  
  244. BOOL hsc_get_htmlonly(HSCPRC * hp)
  245. {
  246.     return (hp->htmlonly);
  247. }
  248.  
  249. BOOL hsc_get_jens(HSCPRC * hp)
  250. {
  251.     return (hp->jens);
  252. }
  253.  
  254. BOOL hsc_get_jerkvalues(HSCPRC * hp)
  255. {
  256.     return (hp->jerkvalues);
  257. }
  258.  
  259. BOOL hsc_get_rplc_ent(HSCPRC * hp)
  260. {
  261.     return (hp->rplc_ent);
  262. }
  263.  
  264. BOOL hsc_get_rplc_quote(HSCPRC * hp)
  265. {
  266.     return (hp->rplc_quote);
  267. }
  268.  
  269. BOOL hsc_get_smart_ent(HSCPRC * hp)
  270. {
  271.     return (hp->smart_ent);
  272. }
  273.  
  274. BOOL hsc_get_strip_badws(HSCPRC * hp)
  275. {
  276.     return (hp->strip_badws);
  277. }
  278.  
  279. BOOL hsc_get_strip_cmt(HSCPRC * hp)
  280. {
  281.     return (hp->strip_cmt);
  282. }
  283.  
  284. BOOL hsc_get_strip_ext(HSCPRC * hp)
  285. {
  286.     return (hp->strip_ext);
  287. }
  288.  
  289. /*
  290.  * get internal flags
  291.  */
  292. BOOL hsc_get_suppress_output(HSCPRC * hp)
  293. {
  294.     return (hp->suppress_output);
  295. }
  296.  
  297. BOOL hsc_get_inside_pre(HSCPRC * hp)
  298. {
  299.     return (hp->inside_pre);
  300. }
  301.  
  302. BOOL hsc_get_inside_anchor(HSCPRC * hp)
  303. {
  304.     return (hp->inside_anchor);
  305. }
  306.  
  307. BOOL hsc_get_fatal(HSCPRC * hp)
  308. {
  309.     return (hp->fatal);
  310. }
  311.  
  312. /*
  313.  * get values
  314.  */
  315. STRPTR hsc_get_destdir(HSCPRC * hp)
  316. {
  317.     return (estr2str(hp->destdir));
  318. }
  319.  
  320. STRPTR hsc_get_reldir(HSCPRC * hp)
  321. {
  322.     return (estr2str(hp->reldir));
  323. }
  324.  
  325. STRPTR hsc_get_iconbase(HSCPRC * hp)
  326. {
  327.     return (estr2str(hp->iconbase));
  328. }
  329.  
  330. STRPTR hsc_get_server_dir(HSCPRC * hp)
  331. {
  332.     return (estr2str(hp->server_dir));
  333. }
  334.  
  335.  
  336. /*
  337.  * get internal values
  338.  */
  339. STRPTR hsc_get_click_here_str(HSCPRC * hp)
  340. {
  341.     return (hp->click_here_str);
  342. }
  343.  
  344. STRPTR hsc_get_file_name(HSCPRC * hp)
  345. {
  346.     if (hp->inpf)
  347.         return (infget_fname(hp->inpf));
  348.     else
  349.         return (NULL);
  350. }
  351.  
  352. ULONG hsc_get_file_line(HSCPRC * hp)
  353. {
  354.     if (hp->inpf)
  355.         return (infget_y(hp->inpf));
  356.     else
  357.         return (0);
  358. }
  359.  
  360. ULONG hsc_get_file_column(HSCPRC * hp)
  361. {
  362.     if (hp->inpf)
  363.         return (infget_x(hp->inpf));
  364.     else
  365.         return (0);
  366. }
  367.  
  368. ULONG hsc_get_msg_count(HSCPRC * hp)
  369. {
  370.     return (hp->msg_count);
  371. }
  372.  
  373. /*
  374.  *
  375.  * SET-methodes for public item of HSCPRC
  376.  *
  377.  */
  378.  
  379. /*
  380.  * set values
  381.  */
  382. BOOL hsc_set_destdir(HSCPRC * hp, STRPTR dir)
  383. {
  384.     set_estr(hp->destdir, dir);
  385.     /* append "/" if neccessary */
  386.     link_fname(hp->destdir, estr2str(hp->destdir), "");
  387.     D(fprintf(stderr, DHL "destdir=`%s'\n", estr2str(hp->destdir)));
  388.  
  389.     return (TRUE);
  390. }
  391.  
  392. BOOL hsc_set_reldir(HSCPRC * hp, STRPTR dir)
  393. {
  394. #if 0
  395.     set_estr(hp->reldir, dir);
  396.     /* append "/" if neccessary */
  397.     link_fname(hp->reldir, estr2str(hp->reldir), "");
  398.     D(fprintf(stderr, DHL "reldir =`%s'\n", estr2str(hp->reldir)));
  399. #endif
  400.     /* append "/" if neccessary */
  401.     link_fname(hp->reldir, dir, "");
  402.     D(fprintf(stderr, DHL "reldir =`%s'\n", estr2str(hp->reldir)));
  403.  
  404.     return (TRUE);
  405. }
  406.  
  407. BOOL hsc_set_iconbase(HSCPRC * hp, STRPTR uri)
  408. {
  409.     set_estr(hp->iconbase, uri);
  410.  
  411.     D(fprintf(stderr, DHL "iconbase=`%s'\n", estr2str(hp->iconbase)));
  412.  
  413.     return (TRUE);
  414. }
  415.  
  416. BOOL hsc_set_server_dir(HSCPRC * hp, STRPTR dir)
  417. {
  418.     set_estr(hp->server_dir, dir);
  419.  
  420.     /* if dir does not already end with a directory separator,
  421.      * append if now */
  422.     if (!strchr(PATH_SEPARATOR, last_ch(dir)))
  423.     {
  424.         app_estrch(hp->server_dir, PATH_SEPARATOR[0]);
  425.     }
  426.  
  427.     D(fprintf(stderr, DHL "serverdir=`%s'\n", estr2str(hp->server_dir)));
  428.  
  429.     return (TRUE);
  430. }
  431.  
  432. BOOL hsc_set_strip_tags(HSCPRC * hp, STRPTR taglist)
  433. {
  434.     reallocstr(&(hp->strip_tags), taglist);
  435.     return (TRUE);
  436. }
  437.  
  438. BOOL hsc_set_filename_document(HSCPRC * hp, STRPTR filename)
  439. {
  440.     BOOL ok = FALSE;
  441.  
  442.     D(fprintf(stderr, DHL "document=`%s'\n", filename));
  443.     hp->filename_document = strclone(filename);
  444.  
  445.     return (ok);
  446. }
  447.  
  448. /*
  449.  * set flags
  450.  */
  451. VOID hsc_set_chkid(HSCPRC * hp, BOOL new_chkid)
  452. {
  453.     hp->chkid = new_chkid;
  454.     D(fprintf(stderr, DHL "flag: chkid    =%d\n", new_chkid));
  455. }
  456.  
  457. VOID hsc_set_chkuri(HSCPRC * hp, BOOL new_chkuri)
  458. {
  459.     hp->chkuri = new_chkuri;
  460.     D(fprintf(stderr, DHL "flag: chkuri   =%d\n", new_chkuri));
  461. }
  462.  
  463. VOID hsc_set_compact(HSCPRC * hp, BOOL new_compact)
  464. {
  465.     hp->compact = new_compact;
  466.     D(fprintf(stderr, DHL "flag: compact  =%d\n", new_compact));
  467. }
  468.  
  469. VOID hsc_set_debug(HSCPRC * hp, BOOL new_debug)
  470. {
  471.     hp->debug = new_debug;
  472.     D(fprintf(stderr, DHL "flag: debug    =%d\n", new_debug));
  473. }
  474.  
  475. VOID hsc_set_getsize(HSCPRC * hp, BOOL new_getsize)
  476. {
  477.     hp->getsize = new_getsize;
  478.     D(fprintf(stderr, DHL "flag: getsize  =%d\n", new_getsize));
  479. }
  480.  
  481. VOID hsc_set_htmlonly(HSCPRC * hp, BOOL new_htmlonly)
  482. {
  483.     hp->htmlonly = new_htmlonly;
  484.     D(fprintf(stderr, DHL "flag: htmlonly =%d\n", new_htmlonly));
  485. }
  486.  
  487. VOID hsc_set_jens(HSCPRC * hp, BOOL new_jens)
  488. {
  489.     hp->jens = new_jens;
  490.     D(fprintf(stderr, DHL "flag: jens     =%d\n", new_jens));
  491. }
  492.  
  493. VOID hsc_set_jerkvalues(HSCPRC * hp, BOOL new_jerkvalues)
  494. {
  495.     hp->jerkvalues = new_jerkvalues;
  496.     D(fprintf(stderr, DHL "flag: jerkval  =%d\n", new_jerkvalues));
  497. }
  498.  
  499. VOID hsc_set_rplc_ent(HSCPRC * hp, BOOL new_rplc_ent)
  500. {
  501.     hp->rplc_ent = new_rplc_ent;
  502.     D(fprintf(stderr, DHL "flag: rplc_ent =%d\n", new_rplc_ent));
  503. }
  504.  
  505. VOID hsc_set_rplc_quote(HSCPRC * hp, BOOL new_rplc_quote)
  506. {
  507.     hp->rplc_quote = new_rplc_quote;
  508.     D(fprintf(stderr, DHL "flag: rplc_quote =%d\n", new_rplc_quote));
  509. }
  510.  
  511. VOID hsc_set_smart_ent(HSCPRC * hp, BOOL new_smart_ent)
  512. {
  513.     hp->smart_ent = new_smart_ent;
  514.     D(fprintf(stderr, DHL "flag: smart_ent=%d\n", new_smart_ent));
  515. }
  516.  
  517. VOID hsc_set_strip_badws(HSCPRC * hp, BOOL new_strip_badws)
  518. {
  519.     hp->strip_badws = new_strip_badws;
  520.     D(fprintf(stderr, DHL "flag: strip_bws=%d\n", new_strip_badws));
  521. }
  522.  
  523. VOID hsc_set_strip_cmt(HSCPRC * hp, BOOL new_strip_cmt)
  524. {
  525.     hp->strip_cmt = new_strip_cmt;
  526.     D(fprintf(stderr, DHL "flag: strip_cmt=%d\n", new_strip_cmt));
  527. }
  528.  
  529. VOID hsc_set_strip_ext(HSCPRC * hp, BOOL new_strip_ext)
  530. {
  531.     hp->strip_ext = new_strip_ext;
  532.     D(fprintf(stderr, DHL "flag: strip_ext=%d\n", new_strip_ext));
  533. }
  534.  
  535. /*
  536.  * set flags
  537.  */
  538. VOID hsc_set_quote_mode(HSCPRC * hp, LONG new_mode)
  539. {
  540.     hp->quotemode = new_mode;
  541.     D(fprintf(stderr, DHL "quote_mode=%ld\n", new_mode));
  542. }
  543.  
  544. VOID hsc_set_entity_mode(HSCPRC * hp, LONG new_mode)
  545. {
  546.     hp->entmode = new_mode;
  547.     D(fprintf(stderr, DHL "entity_mode=%ld\n", new_mode));
  548. }
  549.  
  550. /*
  551.  * set call-backs
  552.  */
  553. VOID hsc_set_status_file_begin(HSCPRC * hp, VOID(*status_file) (HSCPRC * hp, STRPTR filename))
  554. {
  555.     hp->CB_status_file_begin = status_file;
  556. }
  557.  
  558. VOID hsc_set_status_file_end(HSCPRC * hp, VOID(*status_file) (HSCPRC * hp))
  559. {
  560.     hp->CB_status_file_end = status_file;
  561. }
  562.  
  563. VOID hsc_set_status_line(HSCPRC * hp, VOID(*status_line) (HSCPRC * hp))
  564. {
  565.     hp->CB_status_line = status_line;
  566. }
  567.  
  568. VOID hsc_set_status_misc(HSCPRC * hp, VOID(*status_misc) (HSCPRC * hp, STRPTR s))
  569. {
  570.     hp->CB_status_misc = status_misc;
  571. }
  572.  
  573. VOID hsc_set_message(
  574.                         HSCPRC * hp,
  575.                         VOID(*message) (struct hsc_process * hp,
  576.                                         HSCMSG_CLASS msg_class, HSCMSG_ID msg_id,
  577.                                         STRPTR fname, ULONG x, ULONG y,
  578.                                         STRPTR msg_text))
  579. {
  580.     hp->CB_message = message;
  581. }
  582.  
  583. VOID hsc_set_message_ref(
  584.                             HSCPRC * hp,
  585.                             VOID(*message_ref) (struct hsc_process * hp,
  586.                                    HSCMSG_CLASS msg_class, HSCMSG_ID msg_id,
  587.                                              STRPTR fname, ULONG x, ULONG y,
  588.                                                 STRPTR msg_text))
  589. {
  590.     hp->CB_message_ref = message_ref;
  591. }
  592.  
  593. VOID hsc_set_start_tag(HSCPRC * hp,
  594.                        VOID(*start_tag) (struct hsc_process * hp,
  595.           HSCTAG * tag, STRPTR tag_name, STRPTR tag_attr, STRPTR tag_close))
  596. {
  597.     hp->CB_start_tag = start_tag;
  598. }
  599.  
  600. VOID hsc_set_end_tag(HSCPRC * hp,
  601.                      VOID(*end_tag) (struct hsc_process * hp,
  602.           HSCTAG * tag, STRPTR tag_name, STRPTR tag_attr, STRPTR tag_close))
  603. {
  604.     hp->CB_end_tag = end_tag;
  605. }
  606.  
  607. VOID hsc_set_text(HSCPRC * hp,
  608.                   VOID(*text) (struct hsc_process * hp,
  609.                                STRPTR white_spaces, STRPTR text))
  610. {
  611.     hp->CB_text = text;
  612. }
  613.  
  614. VOID hsc_set_id(HSCPRC * hp,
  615.                 VOID(*id) (struct hsc_process * hp,
  616.                            HSCATTR * attr, STRPTR id))
  617. {
  618.     hp->CB_id = id;
  619. }
  620.  
  621. /*
  622.  * message methodes
  623.  */
  624. BOOL hsc_set_msg_ignore(HSCPRC * hp, HSCMSG_ID msg_id, HSCIGN value)
  625. {
  626.     BOOL set = FALSE;
  627.  
  628.     if ((msg_id & MASK_MESSAGE) <= MAX_MSGID)
  629.         hp->msg_ignore[msg_id & MASK_MESSAGE] = value;
  630.  
  631.     return (set);
  632. }
  633.  
  634. HSCIGN hsc_get_msg_ignore(HSCPRC * hp, HSCMSG_ID msg_id)
  635. {
  636.     /* HSCMSG_ID max_msgid = MAX_MSGID; */
  637.     if ((msg_id & MASK_MESSAGE) <= MAX_MSGID)
  638.     {
  639.         return (hp->msg_ignore[msg_id & MASK_MESSAGE]);
  640.     }
  641.     else
  642.     {
  643.         return (FALSE);
  644.     }
  645. }
  646.  
  647. BOOL hsc_set_msg_class(HSCPRC * hp, HSCMSG_ID msg_id, HSCMSG_CLASS msg_class)
  648. {
  649.     BOOL set = FALSE;
  650.  
  651.     if ((msg_id & MASK_MESSAGE) <= MAX_MSGID)
  652.     {
  653.         hp->msg_class[msg_id & MASK_MESSAGE] = msg_class;
  654.     }
  655.  
  656.     return (set);
  657. }
  658.  
  659. HSCMSG_CLASS hsc_get_msg_class(HSCPRC * hp, HSCMSG_ID msg_id)
  660. {
  661.     HSCMSG_ID msg_id_unmasked = msg_id & MASK_MESSAGE;
  662.     if (msg_id_unmasked <= MAX_MSGID)
  663.     {
  664.         HSCMSG_CLASS mchp = hp->msg_class[msg_id_unmasked];
  665.         HSCMSG_CLASS mcid = msg_id & MASK_MSG_CLASS;
  666.  
  667.         if (mcid > mchp)
  668.         {
  669.             return (mcid);
  670.         }
  671.         else
  672.         {
  673.             return (mchp);
  674.         }
  675.     }
  676.     else
  677.         return (MSG_NONE);
  678. }
  679.  
  680. /*
  681.  * set message classes to be ignored
  682.  */
  683. BOOL hsc_get_msg_ignore_notes(HSCPRC * hp)
  684. {
  685.     return hp->msg_ignore_notes;
  686. }
  687.  
  688. BOOL hsc_get_msg_ignore_style(HSCPRC * hp)
  689. {
  690.     return hp->msg_ignore_style;
  691. }
  692.  
  693. BOOL hsc_get_msg_ignore_port(HSCPRC * hp)
  694. {
  695.     return hp->msg_ignore_port;
  696. }
  697.  
  698. BOOL hsc_set_msg_ignore_notes(HSCPRC * hp, BOOL value)
  699. {
  700.     hp->msg_ignore_notes = value;
  701.     return (value);
  702. }
  703.  
  704. BOOL hsc_set_msg_ignore_style(HSCPRC * hp, BOOL value)
  705. {
  706.     hp->msg_ignore_style = value;
  707.     return (value);
  708. }
  709.  
  710. BOOL hsc_set_msg_ignore_port(HSCPRC * hp, BOOL value)
  711. {
  712.     hp->msg_ignore_port = value;
  713.     return (value);
  714. }
  715.  
  716.  
  717. /*
  718.  * reset whole arrays for message-class/ignores
  719.  */
  720. VOID hsc_clear_msg_ignore(HSCPRC * hp)
  721. {
  722.     size_t i;
  723.     for (i = 0; i <= MAX_MSGID; i++)
  724.         hp->msg_ignore[i] = FALSE;
  725. }
  726.  
  727. VOID hsc_reset_msg_class(HSCPRC * hp)
  728. {
  729.     size_t i;
  730.     for (i = 0; i <= MAX_MSGID; i++)
  731.         hp->msg_class[i] = MSG_NONE;
  732. }
  733.  
  734. /*
  735.  * methods for include-directories
  736.  */
  737. BOOL hsc_add_include_directory(HSCPRC * hp, STRPTR dir)
  738. {
  739.     return ((BOOL) (app_strnode(hp->include_dirs, dir) != NULL));
  740. }
  741.  
  742. VOID hsc_clr_include_directory(HSCPRC * hp)
  743. {
  744.     clr_strlist(hp->include_dirs);
  745. }
  746.  
  747. /*
  748.  *-------------------------------------
  749.  * misc. funtions for white spaces
  750.  *-------------------------------------
  751.  */
  752.  
  753. /*
  754.  * compactWs - reduce white space string to blank
  755.  *             or linefeed
  756.  */
  757. STRPTR compactWs(HSCPRC * hp, STRPTR ws)
  758. {
  759.     STRPTR newWs = "";
  760.  
  761.     if (ws[0])
  762.     {
  763.         /* any white spaces at all */
  764.         STRPTR containsLF = strchr(ws, '\n');
  765.         STRPTR containsCR = strchr(ws, '\r');
  766.  
  767.         if (containsLF)
  768.             if (containsCR)
  769.                 newWs = "\r\n";
  770.             else
  771.                 newWs = "\n";
  772.         else if (containsCR)
  773.             newWs = "\r";
  774.         else
  775.             newWs = " ";
  776.     }
  777.  
  778.     return (newWs);
  779. }
  780.  
  781. /*
  782.  * output text function
  783.  *
  784.  * output text to host process
  785.  *
  786.  * params: hp....hsc process to perform ouput with
  787.  *         wspc..white spaces
  788.  *         text..other text
  789.  * result: true, if text has been outputted
  790.  */
  791. BOOL hsc_output_text(HSCPRC * hp, STRPTR wspc, STRPTR text)
  792. {
  793.     BOOL written = FALSE;
  794.     if ((hp)->CB_text && !((hp)->suppress_output))
  795.     {
  796.         /* add current white spaces to white space
  797.          * buffer; if hp->compact is enabled, reduce
  798.          * white spaces */
  799.         if (wspc)
  800.         {
  801.             app_estr(hp->whtspc, wspc);
  802.         }
  803.         if (hp->compact && (!hp->inside_pre))
  804.         {
  805.             /* reduce white spaces */
  806.             wspc = compactWs(hp, estr2str(hp->whtspc));
  807.         }
  808.         else
  809.         {
  810.             wspc = estr2str(hp->whtspc);
  811.         }
  812.  
  813.         /* strip white spaces if requested */
  814.         if (hp->strip_next_whtspc)
  815.         {
  816.             D(fprintf(stderr, DHL "bad white spaces stripped\n"));
  817.             hp->strip_next_whtspc = FALSE;
  818.             wspc = "";
  819.         }
  820.         else if (hp->strip_next2_whtspc)
  821.         {
  822.             hp->strip_next2_whtspc = FALSE;
  823.             hp->strip_next_whtspc = TRUE;
  824.         }
  825.         else if ((hp->tag_next_whtspc)
  826.                  && strlen(wspc))
  827.         {
  828.             hsc_message(hp, MSG_SUCC_WHTSPC,
  829.                         "succeeding white-space for %T",
  830.                         hp->tag_next_whtspc);
  831.         }
  832.  
  833.         hp->tag_next_whtspc = NULL;
  834.  
  835.  
  836. #if DEBUG_HSCLIB_OUTPUT
  837.         if (hp->debug)
  838.             if (text)
  839.                 if (strcmp(text, "\n"))
  840.                     fprintf(stderr, DHL "ouput: `%s', `%s'\n", wspc, text);
  841.                 else
  842.                     fprintf(stderr, DHL "ouput: `%s', `\\n'\n", wspc);
  843. #endif
  844.         if ((wspc && wspc[0]) || (text && text[0]))
  845.         {
  846.             /* convert NULL values to empty strings */
  847.             if (!wspc)
  848.             {
  849.                 wspc = "";
  850.             }
  851.             if (!text)
  852.             {
  853.                 text = "";
  854.             }
  855.  
  856.             /* output text */
  857.             (*((hp)->CB_text)) ((hp), wspc, text);
  858.             written = TRUE;
  859.         }
  860.  
  861.         /* reset white space buffer */
  862.         clr_estr(hp->whtspc);
  863.  
  864.     }
  865.     return (written);
  866. }
  867.  
  868. /*
  869.  * misc. functions
  870.  */
  871.  
  872. /*
  873.  * nomem-handler
  874.  */
  875. BOOL hsc_standard_nomem_handler(size_t size)
  876. {                               /* TODO: think about this */
  877.     fputs("\n*** out of memory\n\n", stderr);
  878.  
  879.     exit(RC_FAIL);
  880.  
  881.     return (FALSE);             /* abort immediatly */
  882. }
  883.  
  884.